package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.TopicQueryBean;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    @RequestMapping("list")
    public BaseRespVo list(TopicQueryBean topicQueryBean){
        Map topicMap = topicService.queryTopic(topicQueryBean);
        return BaseRespVo.ok(topicMap);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Topic requestTopic){
        BaseRespVo baseRespVo = new BaseRespVo();
        Topic topic = topicService.createTopic(requestTopic);
        return BaseRespVo.ok(topic);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Topic requestTopic){
        BaseRespVo baseRespVo = new BaseRespVo();
        Topic updateTopic = topicService.updateTopic(requestTopic);
        return BaseRespVo.ok(updateTopic);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Topic topic){
        BaseRespVo baseRespVo = new BaseRespVo();
        int code = topicService.deleteById(topic);
        return BaseRespVo.ok();
    }
}
